package com.atguigu.gulimall.search.controller;

import com.atguigu.common.to.es.SkuEsModel;
import com.atguigu.common.utils.R;
import com.atguigu.gulimall.search.service.ProductSaveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/search")
@Slf4j
public class ElasticsearchSaveController {

    @Autowired
    private ProductSaveService productSaveService;

    /**
     * 商品上架，存储数据到es中
     *
     * @param list
     * @return
     */
    @PostMapping(value = "/product")
    public R productUp(@RequestBody List<SkuEsModel> list) {
        try {
            productSaveService.productUp(list);
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }
}
